package light.head.model;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;

import org.hibernate.annotations.Formula;
/**
 * 物品申请
 *
 */
@Entity
@Table
public class ApplyInfo implements Serializable {

	
	private static final long serialVersionUID = -9217436216362667342L;
	
	
	private Integer code;
	private String title;					// 标题
	private Date at;						// 申请时间
	private Integer au;						// 申请人
	private Integer oc;				      	// 机构编号
	private Boolean deleted;
	private Byte sort;						// 申请类型(1.消耗品2.固定资产)
	private Byte status;					// 领用状况(1.已领用 2.未领用(只要为领用完都算未领用))
	private Double total;					// 总金额
	private String remark;
	
	
	List<ApplyItem> adList;					// 申请明细
	private String an;
	private String ocn;						// 创建机构名称
	private List<AuditStatus> auditStatusList;	// 审核状态
	
	
	
	
	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@Column
	public Integer getCode() {
		return code;
	}
	@Temporal(TemporalType.TIMESTAMP)
	@Column(updatable = false, nullable = false)
	public Date getAt() {
		return at;
	}
	@Column
	public Integer getAu() {
		return au;
	}
	@Column
	public Integer getOc() {
		return oc;
	}
	@Column
	public Boolean getDeleted() {
		return deleted;
	}
	
	@Column(length = 100)
	public String getTitle() {
		return title;
	}
	@Column
	public Byte getSort() {
		return sort;
	}
	@Column
	public String getRemark() {
		return remark;
	}
	@Column
	public Byte getStatus() {
		return status;
	}
	@Formula("(SELECT u.realName FROM UserInfo u WHERE u.code = au )")
	public String getAn() {
		return an;
	}
	
	@Formula("(SELECT o.name FROM Organ o WHERE o.code = oc)")
	public String getOcn() {
		return ocn;
	}
	
	@Transient
	public List<AuditStatus> getAuditStatusList() {
		return auditStatusList;
	}
	
	@Transient
	public List<ApplyItem> getAdList() {
		return adList;
	}
	@Column
	public Double getTotal() {
		return total;
	}
	
	
	
	
	
	public void setTotal(Double total) {
		this.total = total;
	}
	public void setRemark(String remark) {
		this.remark = remark;
	}
	
	public void setStatus(Byte status) {
		this.status = status;
	}
	public void setAuditStatusList(List<AuditStatus> auditStatusList) {
		this.auditStatusList = auditStatusList;
	}
	public void setSort(Byte sort) {
		this.sort = sort;
	}
	public void setTitle(String title) {
		this.title = title;
	}
	public void setAdList(List<ApplyItem> adList) {
		this.adList = adList;
	}
	public void setAn(String an) {
		this.an = an;
	}
	public void setDeleted(Boolean deleted) {
		this.deleted = deleted;
	}
	public void setCode(Integer code) {
		this.code = code;
	}
	public void setAt(Date at) {
		this.at = at;
	}
	public void setAu(Integer au) {
		this.au = au;
	}
	public void setOc(Integer oc) {
		this.oc = oc;
	}
	public void setOcn(String ocn) {
		this.ocn = ocn;
	}
	
	
	// 添加申请明细
	public void addItem(ApplyItem item) {
		if (null == this.adList || this.adList.size() == 0) {
			this.adList = new ArrayList<ApplyItem>();
		}
		this.adList.add(item);
	}
	
}
